/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("material_plan_xie",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using ATkg.BizAppProject.DomainModels;
using ATkg.BizAppProject.IServices;
using Microsoft.AspNetCore.Authorization;
using Newtonsoft.Json.Linq;
using static ATkg.BizAppProject.Services.material_plan_xieService;
using DGZImp.Core.EFDbContext;
using DocumentFormat.OpenXml.Drawing;

namespace ATkg.BizAppProject.Controllers
{
    public partial class material_plan_xieController
    {
        private readonly Imaterial_plan_xieService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;
        //private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly Imaterial_plan_xieRepository _repository;//访问数据库
        public ISqlSugarClient Db = AutofacContainerModule.GetService<ServiceDbContext>()?.SqlSugarClient;
        //public AmesSyncService ames = AutofacContainerModule.GetService<AmesSyncService>();

        [ActivatorUtilitiesConstructor]
        public material_plan_xieController(
            Imaterial_plan_xieService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }


        [HttpGet("cailiao_plan_data_xie")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> cailiao_plan_data_xie()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var r = await Service.get_info_from_bfmes();
            //var r = 0;

            //var r = 0;
            return JsonNormal(r);
        }

        [HttpGet("get_data_db")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> get_data_db()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var r = await Service.get_db_data();
            //var r = 0;

            //var r = 0;
            return JsonNormal(r);
        }

        [HttpGet("get_data_db_compute")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> get_data_db_compute()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var r = await Service.get_db_data_order_compute();
            //var r = 0;

            //var r = 0;
            return JsonNormal(r);
        }


        [HttpGet("get_db_proinfo")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> get_db_proinfo()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var r = await Service.get_db_data_order();
            //var r = 0;

            //var r = 0;
            return JsonNormal(r);
        }

        [HttpGet("get_db_order_plan")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<string> get_db_order_plan(string editingOrder_data)
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {

            Console.WriteLine("get方法调用");
            Console.WriteLine(editingOrder_data);
            JObject plan_data_final = JObject.Parse(editingOrder_data);
            Console.WriteLine(plan_data_final["yx_device"]);


            var r = await Service.get_db_data_order_plan(plan_data_final);
            //(string)plan_data_final["schedule_id"], 
            int rowsAffected = Db.Updateable<MaterialPlan>()
                    .SetColumns(it => new MaterialPlan()
                    {
                        device_type = (string)plan_data_final["device_type"],
                    })
                    .Where(it => it.schedule_id == (string)plan_data_final["schedule_id"]) // 精确条件
                    .ExecuteCommand();


            //var r = 0;
            return r;
        }
        [HttpGet("get_db_eng")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> get_db_eng()

        {
            Console.WriteLine("get方法调用");
            string startTime = "";
            string endtime = "";
            var r = await Service.get_db_get_db_eng(startTime, endtime);
            //Console
            //var r = 0;

            //var r = 0;
            return JsonNormal(r);
        }

        [HttpGet("get_no_plan_order")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> get_no_plan_order()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var r = await Service.get_no_plan_order_detal();
            //var r = 0;

            return JsonNormal(r);
        }


        [HttpGet("update_color_yaji")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<string> update_color_yaji(string order,string color_)
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {

            Console.WriteLine("get方法调用");
            Console.WriteLine(color_);

            //var r = await Service.get_db_data_order_plan(plan_data_final);
            //(string)plan_data_final["schedule_id"], 
            int rowsAffected = Db.Updateable<material_plan_xie_plan>()
                    .SetColumns(it => new material_plan_xie_plan()
                    {
                        color = (string)color_,
                    })
                    .Where(it => it.schedule_id == (string)order) // 精确条件
                    .ExecuteCommand();

            var r = "1111";
            return r;
        }
    }
}
